package models.System.Systems;

import models.System.SQL.SQL;
import models.SystemModels.SystemMeun;
import models.Models.SystemRoteMeunName;
import models.SystemModels.SystemUserMeun;
import models.interfaces.Models;
import play.Play;
import play.libs.Files;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018-06-27.
 */
public class SystemModels implements Models {

    private  Systems systems = new Systems();

    @Override
    public List<SystemMeun> Meun() {
        return null;
    }

    @Override
    public List<SystemUserMeun> UserMeun(String name, String id) {
        return null;
    }


    @Override
    public String Imgs(File file) {
        if(img.img(file).length()>0){
            return null;
        }
        String filePath = String.format("/Img/%s",systems.ids("IMG"));
        Files.copy(file, Play.getFile(filePath));
        return filePath;
    }

    @Override
    public List<SystemRoteMeunName> systemRoteMeunName() {
        Connection conn = BaseDaos.getConnection();
        try {
            PreparedStatement ptmt = conn.prepareStatement(SQL.ROTEMEUN);
            List<SystemRoteMeunName> lists = new ArrayList<SystemRoteMeunName>();
            ResultSet rs = ptmt.executeQuery();
            while (rs.next()) {
                SystemRoteMeunName systemRoteMeunName = new SystemRoteMeunName();
                systemRoteMeunName.setMenuName(rs.getString("MenuName"));
                systemRoteMeunName.setRoteName(rs.getString("RoteName"));
                System.out.println("SystemModels.systemRoteMeunName"+systemRoteMeunName.MenuName+"&"+systemRoteMeunName.RoteName);
                lists.add(systemRoteMeunName);
            }
            return lists;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;

        }
    }
}
